import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
import Want from '@ohos.app.ability.Want';
import { WindowManager } from '../WindowManager';
import { BleCallBack, BleClient } from '../ble/BleClient';
import Log from '../utils/Logger';

const TAG: string = 'ServiceAbility';

export default class ServiceAbility extends ServiceExtensionAbility {

  onCreate() {
    Log.info(TAG, 'ServiceAbility onCreate');

    BleClient.getInstance().init()
    BleClient.getInstance().startFound()
    WindowManager.getInstance().showWindow1(this.context)
    const myBleCallBack: BleCallBack = {
      onData: async (data) => {
        WindowManager.getInstance().showWindow2(this.context)
      }
    };
    BleClient.getInstance().addBleCallBack(myBleCallBack)
  }

  onDestroy(): void {
    Log.info(TAG, 'ServiceAbility onDestroy');
  }

  onRequest(want: Want, startId: number): void {
    Log.info(TAG, 'ServiceAbility onRequest');
    Log.info(TAG, JSON.stringify(want));
    Log.info(TAG, 'startId' + startId.toString());
  }

}